package com.appspot.authorizationdemo.server;

import java.util.ArrayList;

import com.appspot.authorizationdemo.server.authorization.Authorization;
import com.appspot.authorizationdemo.shared.UserRoleType;

/**
 * 
 * @author jeroen.weber
 * Klasse die bestemd is om test data (users) aan te maken in de database.
 * De klasse Authorization voorkomt redundantie
 * 
 */
public class InitializeUsers {
	
	private Authorization auth;

	/**
	 * Initializes Authorization which will be used to add users
	 */
	public InitializeUsers()
	{
		auth = new Authorization();
	}
	
	/**
	 * Creates users by calling addUser returns succes or failure (based on last insertion)
	 * 
	 * @return returns true if the last user is inserted otherwise false will be
	 *         returned
	 */
	public boolean createUsers()
	{
		boolean created = false;

		created = addUser("jeroen.weber@hu.nl", UserRoleType.DOCENT);
		created = addUser("alex.jongman@hu.nl", UserRoleType.DOCENT);
		created = addUser("frank.plattel@student.hu.nl", UserRoleType.STUDENT);
		created = addUser("dylan.drost@student.hu.nl", UserRoleType.STUDENT);	
		return created;
	}
	
	/**
	 * Adds a single user
	 * 
	 * @param email
	 *            the user
	 * @param urt
	 *            a UserRoleTypes.
	 * @return returns true if the user is added succesfully otherwise false will be
	 *         returned
	 */
	private boolean addUser(String email, UserRoleType urt)
	{

		ArrayList<UserRoleType> rights = new ArrayList<UserRoleType>();
		
		rights.add(urt);
		return auth.addUser(email, rights);
	}

}
